using System.Collections.Generic;
using Godot;
using GoGameClient.script.common.button;

namespace GoGameClient.script.node.@select;

public partial class SelectRoleControl : Control
{
    [Signal]
    public delegate void CurrentRoleChangeEventHandler(long id);

    public override void _Ready()
    {
    }

    private void SelectRoleButtonPressed(long id)
    {
        EmitSignal(SignalName.CurrentRoleChange, id);
    }


    public void SetData(List<RoleSimpleRes> res)
    {
        for (var i = 0; i < res.Count; i++)
        {
            ((Control)GetChildren()[i]).Visible = true;
            ((Control)GetChildren()[i]).GetNode<Label>("Name").Text = res[i].Name;
            if (res[i].Sect == "")
            {
                res[i].Sect = "无门派";
            }

            ((Control)GetChildren()[i]).GetNode<Label>("Info").Text = $"{res[i].Sect} {res[i].Level}";
            var texture2D = GD.Load<Texture2D>($"res://resources/role/{res[i].Model}/图片/圆角头像.png");
            ((Control)GetChildren()[i]).GetNode<HighLightButton>("Button").TextureNormal = texture2D;
            ((Control)GetChildren()[i]).GetNode<HighLightButton>("Button").Id = res[i].Id;
            ((Control)GetChildren()[i]).GetNode<HighLightButton>("Button").Button += SelectRoleButtonPressed;
        }
    }
}